package com.atguigu.lease.web.app.service.impl;

import com.atguigu.lease.model.entity.AttrKey;
import com.atguigu.lease.model.entity.RoomAttrValue;
import com.atguigu.lease.web.app.service.AttrKeyService;
import com.atguigu.lease.web.app.service.RoomAttrValueService;
import com.atguigu.lease.web.app.vo.attr.AttrValueVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.lease.model.entity.AttrValue;
import com.atguigu.lease.web.app.service.AttrValueService;
import com.atguigu.lease.web.app.mapper.AttrValueMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author liubo
* @description 针对表【attr_value(房间基本属性值表)】的数据库操作Service实现
* @createDate 2023-07-26 11:12:39
*/
@Service
public class AttrValueServiceImpl extends ServiceImpl<AttrValueMapper, AttrValue>
    implements AttrValueService{
    @Autowired
    private AttrKeyService attrKeyService;
    @Autowired
    private RoomAttrValueService roomAttrValueService;

    @Override
    public List<AttrValueVo> getRoomAttrValueVoListById(Long id) {
        List<AttrValueVo> attrValueVoList = new ArrayList<>();
        List<RoomAttrValue> roomAttrValueList = roomAttrValueService.list(new LambdaQueryWrapper<RoomAttrValue>().eq(RoomAttrValue::getRoomId, id));
        List<AttrValue> attrValueList = new ArrayList<>();
        if (roomAttrValueList != null && !roomAttrValueList.isEmpty()) {
            for (RoomAttrValue roomAttrValue : roomAttrValueList) {
                attrValueList = this.list(new LambdaQueryWrapper<AttrValue>().eq(AttrValue::getId,roomAttrValue.getAttrValueId()));
            }
            for (AttrValue attrValue : attrValueList) {
                AttrValueVo attrValueVo = new AttrValueVo();
                attrValueVo.setId(attrValue.getId());
                attrValueVo.setName(attrValue.getName());
                attrValueVo.setAttrKeyId(attrValue.getAttrKeyId());
                attrValueVo.setAttrKeyName(attrKeyService.getById(attrValue.getAttrKeyId()).getName());
                attrValueVoList.add(attrValueVo);
            }
        }

        return attrValueVoList;
    }
}




